package org.nt4b.schemadoc.core.dao.oracle;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.log4j.Logger;
import org.nt4b.schemadoc.core.dom.Table;
import org.springframework.jdbc.core.RowMapper;


public class TableCommentsMapper implements RowMapper<Table> {
    protected Logger logger = Logger.getLogger(TableCommentsMapper.class);
    
    @Override
    public Table mapRow(final ResultSet rs, final int rowNum) throws SQLException {
        final String tableName = rs.getString("table_name");
        final String comment = rs.getString("comments");
        final String escapedComment = SqlStringEscaper.escape(comment);
        
        final Table result = new Table();
        result.setName(tableName);
        result.setComment(escapedComment);
        
        if (logger.isDebugEnabled()) {
            logger.debug("read comments for table: " + tableName);
        }
        
        return result;
    }
    
}
